package com.xhwl.logistics.bo;

import lombok.Getter;
import lombok.Setter;

import java.time.Duration;

@Setter
@Getter
public class VehiclePayRecordStayTimeBO {

    private Long days;

    private Long hours;

    private Long minutes;

    private Long seconds;

    public String toStayTimeString() {
        return days + "天" + hours + "小时" + minutes + "分钟" + seconds + "秒";
    }

    public static VehiclePayRecordStayTimeBO vehiclePayRecordStayTimeBO(Integer freeTimeSeconds) {
        VehiclePayRecordStayTimeBO vehiclePayRecordStayTimeBO = new VehiclePayRecordStayTimeBO();

        Duration duration = Duration.ofSeconds(freeTimeSeconds);
        long days = duration.toDays();
        if (days != 0) {
            duration = duration.minusDays(days);
        }
        long hours = duration.toHours();
        if (hours != 0) {
            duration = duration.minusHours(hours);
        }
        long minutes = duration.toMinutes();
        if (minutes != 0) {
            duration = duration.minusMinutes(minutes);
        }
        long seconds = duration.getSeconds();

        vehiclePayRecordStayTimeBO.setDays(days);
        vehiclePayRecordStayTimeBO.setHours(hours);
        vehiclePayRecordStayTimeBO.setMinutes(minutes);
        vehiclePayRecordStayTimeBO.setSeconds(seconds);

        return vehiclePayRecordStayTimeBO;
    }

}
